package com.yxy.mapper;

import com.yxy.pojo.entity.Visit;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VisitMapper {
    /**
     * 添加访问记录
     * @param visit
     */
    void add(Visit visit);

    /**
     * 根据用户id查询访问记录
     * @param userId
     * @return
     */
    @Select("select * from visit where user_id = #{userId}")
    List<Visit> selectByUserId(int userId);

    /**
     * 获取总访问量
     * @return
     */
    @Select("select count(*) from visit")
    int getTotalVisit();

    /**
     * 获取昨天的访问量
     * @return
     */
    @Select("select count(*) from visit where date(visit_time) = curdate() - interval 1 day")
    int getYesterdayVisit();

    /**
     * 获取近上周的访问量
     * @return
     */
    @Select("select count(*) from visit where yearweek(date_format(visit_time, '%Y-%m-%d'), 1) = yearweek(date_sub(curdate(), interval 1 week ), 1)")
    int getLastWeekVisit();

    /**
     * 获取指定日期访问量
     * @param days
     * @return
     */
    int getVisitCount(String date);
}
